package com.example.blog.config;

import com.example.blog.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器，防止用户未登录
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器对象
        registry.addInterceptor(loginInterceptor)
                //设置生效路径
                .addPathPatterns("/user/*")
                .addPathPatterns("/blog/*")
                .excludePathPatterns("/user/login");
    }
}
